<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    var arr = [7,6,5,4,3];
    console.log(arr);

    // 规则：将数组中的数据，两两比较，小的放前面，大的放后面

    // 0~1, 1~2, 2~3, 3~4       0 ~ length-1-0
    // [6, 5, 4, 3, 7]
    // 0~1, 1~2, 2~3            0 ~ length-1-1
    // [5, 4, 3, 6, 7]
    // 0~1, 1~2                 0 ~ length-1-2
    // [4, 3, 5, 6, 7]
    // 0~1                      0 ~ length-1-3
    // [3, 4, 5, 6, 7]

    for(var i=0;i<arr.length-1;i++){
        for(var j=0;j<arr.length-1-i;j++){
            if( arr[j] > arr[j+1] ){
                var x = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = x;
            }
        }
    }
    
    console.log(arr);



    
</script>
</html>